package com.chaos.framework.starter.config;

import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Slf4j
@Configuration
public class ShutdownHookConfig {

    @Resource
    private NacosAutoServiceRegistration nacosAutoServiceRegistration;


    @PostConstruct
    public void init() {
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            log.info("Shutting down hook start");
            nacosAutoServiceRegistration.destroy();
            log.info("Shutting down hook end");
        }));

    }

}
